package org.idtem.UI;
import java.awt.Component;
import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

import org.idtem.UI.dataTypes.TokenExtendidoUI;
import org.idtem.component.wordnet.datatypes.DataTypeSynset;

class SenseDesambiguationTreeCellRenderer extends DefaultTreeCellRenderer  {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	Icon _SelectedSenseIcon;
    Icon _UnselectedSenseIcon;
    Icon _wordIcon;

    public SenseDesambiguationTreeCellRenderer(Icon selectedSenseIcon, Icon unselectedSenseIcon, Icon wordIcon) {
    	_SelectedSenseIcon = selectedSenseIcon;
    	_UnselectedSenseIcon = unselectedSenseIcon;
    	_wordIcon = wordIcon;
    }

    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
        super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
        if (value != null) {
        	DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
        	if (node == null)
        		return this;
        	if (node.getLevel() == 1)
        	{
        		setIcon(_wordIcon);
        		setToolTipText("Word to desambiguate!.");
        	}else if (node.getLevel() == 2)
        	{
        		Object obj = node.getUserObject();
        		DataTypeSynset synset = (DataTypeSynset)obj;
        		DefaultMutableTreeNode parent = (DefaultMutableTreeNode)node.getParent();
        		TokenExtendidoUI tokenExtUI = (TokenExtendidoUI)parent.getUserObject();
        		if (tokenExtUI.isSelectedSense(synset))
        		{
        			setIcon(_SelectedSenseIcon);
        			setToolTipText("Selected sense!.");
        		}else
        		{
        			setIcon(_UnselectedSenseIcon);
        			setToolTipText("Click for select this sense!.");
        		}
        	}
        	
        }
        return this;
    }

}